package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"gocv.io/x/gocv"
	"io/ioutil"
	"log"
	"net/http"
)

func main(){
	mat := gocv.IMRead("/home/gccai/distributed-application/5.jpg", gocv.IMReadColor)
	buf, err := gocv.IMEncode(gocv.JPEGFileExt,mat)
	if err != nil {
		log.Println("1.",err.Error())
		return
	}
	reader:= bytes.NewReader(buf.GetBytes())
	resp, err := http.Post("http://localhost:8002/predict", "image/jpeg", reader)
	if err != nil {
		log.Println("2.",err.Error())
		return
	}
	b, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Println("3",err.Error())
		return
	}
	defer resp.Body.Close()
	var res map[string]bool
	_ = json.Unmarshal(b,&res)

	fmt.Println(res)
}